<?php
// +----------------------------------------------------------------------
// | 商品分类业务逻辑
// +----------------------------------------------------------------------
// | Author: myh
// +----------------------------------------------------------------------
namespace app\admin\service;

use app\common\model\GoodsCategoryModel;

class GoodsCategoryService
{
    /**
     * 新增
     * @param  array  $data  新增的数据
     * @return int
     */
    public static function save($data){
        $model = new GoodsCategoryModel;
        $model->save($data);
        return success($model->id);
    }

    /**
     * 更新
     * @param  array  $data 更新的数据
     * @return int
     */
    public static function update($data){
        $model = GoodsCategoryModel::find($data['id']);
        if(!$model){
            return failure(config('error.er15')['code'],config('error.er15')['msg']);
        }
        return success($model->save($data));
    }

    /**
     * 删除
     * @param  string  $ids  需要删除数据的id
     */
    public static function destroy($ids){
        if(!empty($ids)){
            GoodsCategoryModel::deleteById($ids);
        }
        return success();
    }

    /**
     * 列表
     * @return array
     */
    public static function listTree(){
        $list = GoodsCategoryModel::order('sort desc')->select();
        return success(treeData($list));
    }


}